﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeavenBAL;
using FortuneHeavenCommon.DataMap;
using System.Text;

namespace FortuneHeaven.Web.Lottery
{
    public partial class LotteryShow : System.Web.UI.Page
    {
        private int maxcount = 12;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LotteryOrderBO lotterybo = new LotteryOrderBO();
                List<LotteryOrder> orders = lotterybo.GetTopList(6);
                int gap =orders.Count;
                if (gap <= 3)
                {
                    for (int i = gap; i < 3; i++)
                    {
                        orders.Add(new LotteryOrder()
                            {
                                UserName = "",
                                RequestTime = DateTime.MinValue
                            });
                    }
                    orders.AddRange(orders);
                }
                else
                {
                    for (int i = gap; i < 6; i++)
                    {
                        orders.Add(new LotteryOrder()
                        {
                            UserName = "",
                            RequestTime = DateTime.MinValue
                        });
                    }
                }
                this.rpLotteryOrders.DataSource = orders;
                this.rpLotteryOrders.DataBind();
                this.ltTotal.Text = lotterybo.GetTotalCount().ToString();
                NewsBO newbo = new NewsBO();
                News list = newbo.GetNewsByTitle("抽奖名单");
                if (list != null)
                {
                    string content = list.Content;
                    string[] userlist = content.Split('|');
                    StringBuilder builder = new StringBuilder();

                    for (int index = 0; index < userlist.Length && index < maxcount; index++)
                    {
                        string temp = userlist[index];
                        string[] single = temp.Split(',');
                        if (single.Length == 3)
                        {
                            builder.AppendLine("<tr>");
                            builder.AppendLine("<td width=\"40%\" height=\"25\">");
                            builder.AppendLine("<a href=\"#\">" + single[0] + "</a>");
                            builder.AppendLine("</td>");
                            builder.AppendLine("<td width=\"33%\">");
                            builder.AppendLine(single[1]);
                            builder.AppendLine("</td>");
                            builder.AppendLine("<td width=\"27%\">");
                            builder.AppendLine(single[2]);
                            builder.AppendLine("</td>");
                            builder.AppendLine("</tr>");
                        }
                    }
                    ltWinList.Text = builder.ToString();
                }
            }
        }
    }
}